package com.chuangjiangx.member.stored.ddd.domain.model;

import com.chuangjiangx.dddbase.domain.shared.Timestamp;
import com.chuangjiangx.domain.shared.model.PayTerminal;
import com.chuangjiangx.member.basic.ddd.domain.model.MemberId;
import com.chuangjiangx.member.basic.ddd.domain.model.MerchantId;
import lombok.Getter;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @author cj-ch
 * @date 2018/4/12 上午11:51
 */
@Getter
public class MbrOrderRefundMirror  {
    private Long id;
    private Date createTime;
    private Date updateTime;
    private Long mbrOrderId;

    private String mbrRefundNumber;

    private Long merchantId;

    private Long merchantUserId;

    private Long memberId;

    private Long storeId;

    private Long storeUserId;

    private MbrOrderRefundStatus status;

    private BigDecimal refundAmount;

    private Date refundTime;

    private PayTerminal terminal;



    public static final MbrOrderRefundMirror of(MbrOrderRefund refund){
        MbrOrderRefundMirror mirror = new MbrOrderRefundMirror();
        mirror.id = refund.getId().getId();
        Timestamp timestamp = refund.getTimestamp();
        if(null != timestamp){
            mirror.createTime = timestamp.getCreateTime();
            mirror.updateTime = timestamp.getUpdateTime();
        }
        mirror.mbrOrderId = refund.getMbrOrderId().getId();
        mirror.mbrRefundNumber = refund.getMbrRefundNumber();
        mirror.merchantId = refund.getMerchantId().getId();
        mirror.merchantUserId = refund.getMerchantUserId();
        mirror.storeId = refund.getStoreId();
        mirror.storeUserId = refund.getStoreUserId();
        mirror.memberId = refund.getMemberId().getId();
        mirror.refundAmount = refund.getRefundAmount();
        mirror.refundTime = refund.getRefundTime();
        mirror.status = refund.getStatus();
        mirror.terminal = refund.getTerminal();
        return mirror;
    }

    public MbrOrderRefund convertToMbrOrderRefund(){
        MbrOrderRefund o = new MbrOrderRefund(
                new MbrOrderId(mbrOrderId),
                mbrRefundNumber,
                new MerchantId(merchantId),
                merchantUserId,
                new MemberId(memberId),
                storeId,
                storeUserId,
                status,
                refundAmount,
                refundTime,
                terminal
        );
        o.setId(new MbrOrderRefundId(id));
        o.setTimestamp(new Timestamp(createTime,updateTime));
        return o;
    }
}
